import Vue from 'vue'
import axios from 'axios'
// 因为vue是全局的,所以''内只需要导入vue即可,不需要输入路径
import VueRouter from 'vue-router'
import login from '../views/login/login.vue'
import layout from '@/views/layout/layout.vue'
import business from '@/views/layout/business/business.vue'
import chart from '@/views/layout/chart/chart.vue'
import question from '@/views/layout/question/question.vue'
import subject from '@/views/layout/subject/subject.vue'
import user from '@/views/layout/user/user.vue'
// 导入进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

let _fetch = axios.create({
  baseURL: process.env.VUE_APP_URL,
  withCredentials: true
})
Vue.prototype.$axios = _fetch
Vue.use(VueRouter)
const router = new VueRouter({
  routes: [
    {
      path: '/login',
      component: login, meta: {
        title:'登录页'
    } 
    },
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/layout',
      component: layout,
      children: [
          {
              path: '/layout/business', component: business, meta: {
            title:'企业列表'
        } },
        { path: '/layout/chart', component: chart , meta: {
            title:'数据概览'
        } },
        { path: '/layout/question', component: question , meta: {
            title:'题库列表'
        } },
        { path: '/layout/subject', component: subject , meta: {
            title:'学科列表'
        } },
        { path: '/layout/user', component: user , meta: {
            title:'用户列表'
        } }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
    // 路由进入前处理
    console.log(to);
    console.log(from);
    NProgress.start()
    next()
})
router.afterEach((to, from) => {
    // 路由进入后的处理
    console.log(to);
    console.log(from);
    document.title = to.meta.title
        NProgress.done() 
    
})
export default router
